package org.yylnb.openplatform.search.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.yylnb.openplatform.search.service.SearchService;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author RainLin
 * @date 2020/8/1 - 11:15
 */
@WebListener
public class MyContextLoadListener implements ServletContextListener {

    @Value("${spring.elasticsearch.index}")
    private String index;
    @Value("${spring.elasticsearch.type}")
    private String type;

    @Autowired
    private org.yylnb.openplatform.search.service.SearchService SearchService;
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        try {
            SearchService.createIndexAndType(index,type);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}

